package com.mobilesales.android.adapters;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.mobilesales.android.R;
import com.jeremyfeinstein.slidingmenu.lib.*;

public class SlidingMenus {

	private Activity activity;
	private SlidingMenu slidingMenu = null;
	ListView listviewmenu = null;

	public SlidingMenus(Activity activity) {
		this.activity = activity;
		createMenu();
		loadItemMenu();
	}

	/**
	 * Create sliding menu
	 */
	private void createMenu() {
		slidingMenu = new SlidingMenu(this.activity);
		slidingMenu.setMode(SlidingMenu.LEFT);
		slidingMenu.setTouchModeAbove(SlidingMenu.LEFT);
		slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
		slidingMenu.setShadowDrawable(R.drawable.slidingmenu_shadow);

		// Set weight menu = layout menu
		DisplayMetrics dm = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
		int w = dm.widthPixels * 1 / 3;
		Log.i("w size", w + "");
		slidingMenu.setBehindOffset(w);

		slidingMenu.setFadeDegree(0.1f);

		slidingMenu
				.attachToActivity(this.activity, SlidingMenu.SLIDING_CONTENT);

		slidingMenu.setMenu(R.layout.slidingmenu);
	}

	/**
	 * Load item menu
	 */
	private void loadItemMenu() {
		if (slidingMenu != null) {
			String[] arrTen;
			List<String> arr = new ArrayList<String>();
			arrTen = this.activity.getResources().getStringArray(
					R.array.SlidingMenuList);
			for (int i = 0; i < arrTen.length; i++) {
				arr.add(arrTen[i]);
			}
			listviewmenu = (ListView) this.activity
					.findViewById(R.id.slidingMenu_listview);

			ArrayAdapter<String> t = /*
									 * new ArrayAdapter<String>(activity,
									 * android.R.layout.simple_list_item_1,
									 * arrTen);
									 */
			new SlidingMenuAdapter(activity, R.layout.slidingmenu_list_item,
					arr, activity.getClass());
			listviewmenu.setAdapter(t);
		}
	}

	public SlidingMenu getSlidingMenu() {
		return slidingMenu;
	}

}
